<?php
class ProductsController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$this->_helper->layout->setLayout('index');
		$this->view->content = new App_Content_Main('Products');
		$products_model = new List_Products();
		$products = $products_model->getAllProducts();
		$products_by_cat = array();
		foreach($products as $product)
		{
			$products_by_cat[$product["cid"]][] = $product;
		}
		$this->view->products = $products_by_cat;
		$this->view->categories = $products_model->getAllCategories(array_keys($products_by_cat));
		$request = $this->getRequest();
 		$lang = $request->getParam("lang");
 		$path_to_lang = Zend_Registry::get("config")->path->languages.'translations.'.$lang.'.ini';
 		$translation_adapter = new Zend_Translate('ini', $path_to_lang, $lang);
		$this->view->translate()->setTranslator($translation_adapter);
	}

	public function newsAction()
	{
		$this->_helper->layout->setLayout('index');
		$this->view->content = new App_Content_Main('Products', 'News');
		//var_dump($this->view->content); die();
		$products_model = new List_Products();
		$products = $products_model->getAllNewProducts();
		$products_by_cat = array();
		foreach($products as $product)
		{
			$products_by_cat[$product["cid"]][] = $product;
		}
		$this->view->products = $products_by_cat;
		$this->view->categories = $products_model->getAllCategories(array_keys($products_by_cat));
		$request = $this->getRequest();
 		$lang = $request->getParam("lang");
 		$path_to_lang = Zend_Registry::get("config")->path->languages.'translations.'.$lang.'.ini';
 		$translation_adapter = new Zend_Translate('ini', $path_to_lang, $lang);
		$this->view->translate()->setTranslator($translation_adapter);
	}

	public function updateAction()
	{
		$request = $this->getRequest();
		$product = new Table_Products();
		$product->updateAdvice($request->get("product_id"), $request->get("application_advice"));
		$this->_redirect("/lightbox");
	}
}
?>